home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Pascal Super Library
/
Pascal Super Library (CW International)(1997).bin
/
MATH
/
MATHLIB
/
MATHLIB.DOC
next >
Wrap
Text File
|
1993-06-21
|
16KB
|
296 lines
Math Library (MATHLIB) for Turbo Pascal
Copyright (c) 1991,1993 Waldman Sidelines
Harness the Power of the Advanced Coprocessors in Your Programs!
Waldman Sidelines
Cye H. Waldman
Post Office Box 231157
Encinitas, CA 92023-1157
Technical Support on CompuServe: 72245,1337
INTRODUCTION
Turbo Pascal is robbing you of performance in two important ways. First, all
transcendental math functions (trig and exponential) are coded for the 8087
coprocessor and don't take advantage of the advanced instruction set in the
80x87 or 80486. Second, if you use a memory manager (386MAX, HIMEM, etc.) then
your math performance is being compromised. Fortunately, MATHLIB fixes these
problems. MATHLIB is designed specifically for use with the 80x87 coprocessor.
MATHLIB replaces the intrinsic Pascal math functions and adds twenty-three new
ones as well (including the full C/C++ set). It taps the full power of your
80x87 coprocessor and alleviates the memory manager bottleneck.
MATHLIB should be of particular interest to those performing numerically
intensive computations such as scientific and engineering calculations and
graphics applications which require coordinate transformations using
trigonometric relations.
This program is a shareware product. You may distribute the original shareware
disk (not including the source code) to your friends for evaluation. If you
use this program you are expected to register it with Waldman Sidelines.
Your registration fee entitles you to use this software on a single computer
and to make as many copies of this software as you wish for your own backup
purposes. Site licenses are available; call for details. You may not use
MATHLIB in a commercial product; a separate license agreement must be
established with Waldman Sidelines.
Upon receipt of your registration you will receive a disk with the Pascal
source and the assembled object code required to compile the unit. (Contact
the author regarding availability of the assembly language source code.) In
addition, you will receive notifications of future software updates.
LIMIT OF LIABILITY
MATHLIB is distributed as-is. The author disclaims all warranties expressed or
implied. The author will assume no liability for damages either from direct
use of this product or as a consequence of the use of this product.
COPYRIGHT
MATHLIB is copyrighted with all rights reserved to Waldman Sidelines.
TRADEMARKS
Turbo Pascal is a registered trademark of Borland International, Inc.
386MAX is a registered trademark of Qualitas, Inc.
NetRoom is a trademark of Helix Software Company, Inc.
Microsoft and MS-DOS are registered trademarks of Microsoft, Inc.
MATHLIB Documentation Page 1
DESCRIPTION
Two Turbo Pascal 7.0 units (TPU files) are provided with this software. The
MATHLIB unit provides faster floating point calculation by directly accessing
the advanced instruction set of the 80x87 coprocessors. (These are not
accessible to math functions compiled under Turbo Pascal which is limited to
the 8087 instruction set.) The software automatically detects the coprocessor
and provides the optimal code. The unit is in file MATHLIB.TPU. It contains
replacements for the intrinsic system functions (i.e., ARCTAN, COS, EXP, LN,
SIN) as well as twenty-three additional functions. All functions are coded in
assembly language. The TrigStuff unit (in TRIGSTUF.PAS and TRIGSTUF.TPU)
contains the Pascal source code for the twenty-three new functions. This set
of functions includes all those in the standard C/C++ math library. Some
of the functions have different names than in the C/C++ library, however.
The library is intended for users familiar with Turbo Pascal and the use of
units. Those not familiar with units should refer to the Turbo Pascal manuals.
NOTES ON USAGE
1. Functions supported by the library (in alphabetical order):
FUNCTION ACOSH(x: DOUBLE):DOUBLE; { inverse hyperbolic cosine }
FUNCTION ArcCOS(x: DOUBLE):DOUBLE; { inverse cosine function }
FUNCTION ArcSIN(x: DOUBLE):DOUBLE; { inverse sine function }
FUNCTION ARCTAN(x: DOUBLE):DOUBLE; { inverse tangent function }
FUNCTION ArcTangent(x,y: DOUBLE):DOUBLE; { optional inverse tan func }
{ returns arctan(y/x) in the proper quadrant, e.g., 0-360 degrees }
FUNCTION ASINH(x: DOUBLE):DOUBLE; { inverse hyperbolic sine }
FUNCTION ATANH(x: DOUBLE):DOUBLE; { inverse hyperbolic tangent }
FUNCTION CEIL(x: DOUBLE); { smallest integer > x }
FUNCTION COS(x:DOUBLE):DOUBLE; { cosine function }
FUNCTION COSH(x:DOUBLE):DOUBLE; { hyperbolic cosine function }
FUNCTION EXP(x:DOUBLE):DOUBLE; { exponential fn, e^x }
FUNCTION FLOOR(x: DOUBLE); { largest integer < x }
FUNCTION FMOD(x,y:DOUBLE):DOUBLE; { x modulo y }
{ returns remainder f, where x = a*y + f for some integer a & f in [0,y) }
FUNCTION FREXP(x: DOUBLE; VAR n INTEGER);DOUBLE;
{ returns m for which x = m*2^n with m in [0.5,1) }
FUNCTION Expo(x,y:DOUBLE):DOUBLE; { exponential fn, x^y }
FUNCTION HYPOT(x,y: DOUBLE):DOUBLE; { SQRT(SQR(x)+SQR(y)) }
FUNCTION LDEXP(x: DOUBLE; n INTEGER);DOUBLE;{ returns x * 2 ^ n }
FUNCTION LN(x:DOUBLE):DOUBLE; { natural logarithm function }
FUNCTION LOG(x:DOUBLE):DOUBLE; { common logarithm function }
FUNCTION MODF(x: DOUBLE; VAR y DOUBLE);DOUBLE;
{ breaks x into integer and fraction, returns fraction puts integer in y }
FUNCTION POLY(x:DOUBLE; n:INTEGER; VAR degree):DOUBLE;
{ returns y = c0 + c1*x + c2*x^2 + ... + cn*x^n; n = polynomial order }
FUNCTION SIN(x:DOUBLE):DOUBLE; { sine function }
PROCEDURE SINCOS(x:DOUBLE; VAR y,z:DOUBLE); { sine/cosine procedure }
{ returns both sine and cosine; y = SIN(x), z = COS(x) }
FUNCTION SINH(x:DOUBLE):DOUBLE; { hyperbolic sine function }
FUNCTION TAN(x:DOUBLE):DOUBLE; { tangent function }
FUNCTION TANH(x:DOUBLE):DOUBLE; { hyperbolic tangent function }
FUNCTION Ten2TheX(x:DOUBLE):DOUBLE; { exponential fn, 10^x }
FUNCTION Two2TheX(x:DOUBLE):DOUBLE; { exponential fn, 2^x }
MATHLIB Documentation Page 2
2. The library is valid only for type DOUBLE. (The author has found type
DOUBLE to be faster than type REAL.) Contact Waldman Sidelines concerning
other types.
3. The library is compiled in Turbo Pascal 7.0 with the /v option. Object
code is compiled with TASM 3.2 in the IDEAL mode with the TPASCAL MODEL.
4. Standard USES convention; i.e., USES MathLib.
5. Install the TPU file in a directory where Turbo Pascal will find it and
use it in the normal way. E.g., can be USED in other units.
6. This advanced library automatically supersedes the intrinsic math functions.
No explicit action is required on the part of the user.
7. Automatic hardware recognition: the same library will work for '287 and
'387 machines without recompiling.
8. This library has been in use for about four years in mathematical models
of physical systems developed by the author. Speed increases of up to
40% have been observed in computationally intensive programs.
9. Until you become familiar with these programs it would be prudent to
verify that they give the results you expect by comparing output from the
same program compiled with the system and MATHLIB units.
10. Registered users will receive a registration number and all Pascal source
code and assembled object code. The source and object codes will allow
compilation to past and future versions of Turbo Pascal without an
assembler. The registered version does not contain the initialization
shareware information screen.
11. Technical support is available on CompuServe at ID 72245,1337.
CUSTOM VERSIONS
Custom versions of the MATHLIB unit can be developed for your organization.
For example, renaming the functions so that the library can be used
concurrently with the system libraries, or addition of new functions hand coded
in assembly language. Please contact Waldman Sidelines for a quotation.
PERFORMANCE CONSIDERATIONS
The author has run numerous time trials with the library with various systems
('286 through '486) and with and without memory managers installed. The exact
performance increase is sensitive to these two parameters (i.e., coprocessor
and memory manager). However, there is always a substantial performance
increase. If you have a '387 (or '486) you will notice a very strong impact of
using the built-in TAN, SIN, and COS functions and SINCOS procedure in the
80387 instruction set. Also, good advantage is taken of the redefinition of
the ARCTAN and exponentiation instructions as well. The library was tested
extensively for accuracy; a program was developed which drew random arguments
and compared the results of the new library with the standard Pascal results.
MATHLIB Documentation Page 3
A timing program has been included to test on your own system. Try it with and
without your memory manager installed. I've also provided the source code,
but, sorry, I can't give you the timing routine because it's a TurboPower
product. I've also provided the Savage benchmark which I find to be 2.77 times
faster the standard Pascal result (with 386MAX on a 486/33). The effect of
the memory manager is discussed below.
In the course of developing the timing benchmarks it was discovered that the
presence of a memory manager had a rather significant effect on the
performance of the intrinsic math functions in Turbo Pascal. The results with
a memory manager were about 25-40% slower. We found this to be true for three
memory managers we tested (i.e., 386MAX, NetRoom, and Microsoft MS-DOS 5.0
HIMEM/EMM386). We reported this anomalous behavior to Borland who were able
to duplicate this odd result with QEMM as well. Also, there was a great deal
of variability in the results with the memory managers we tested. In our
tests, 386MAX was the fastest and Microsoft MS-DOS 5.0 HIMEM/EMM386 was the
slowest. The question arises as to whether the problem is with Turbo Pascal
or with the memory managers. To answer that question we developed a similar
performance test of the intrinsic math functions in Microsoft FORTRAN. The
memory manager (386MAX, in this case) only slowed down the operations by about
2%, which is about what we would expect. This seems to suggest some
deficiency in Turbo Pascal, but we have no hard core information as yet. The
good news is that the mathematics functions in the library provided herein
appears to be virtually unaffected by the memory mangers. Please share your
own observations with us.
The following table shows the performance increase with MATHLIB realized on
a Club American '486/33 with 386MAX installed.
Speed Speed
Function Ratio Function Ratio
-------- ----- -------- -----
LN 1.88 CEIL 2.19
LOG 2.40 FLOOR 2.64
Two2TheX 3.92 FMOD 2.51
EXP 2.15 FREXP 15.66
Ten2TheX 4.34 HYPOT 1.53
Expo 2.42 LDEXP 11.38
TAN 5.51 MODF 1.77
SIN 2.25 POLY 2.32
COS 2.25 COSH 2.26
SINCOS 4.04 SINH 2.26
ARCTAN 1.93 TANH 2.27
ArcTangent 2.48 ACOSH 2.02
ArcSIN 2.09 ASINH 2.01
ArcCOS 2.87 ATANH 1.90
Demonstration of the POLY function is given in MATHTIME.PAS and TRIGSTUF.PAS
which were used to produce the above results. Source code for these functions
is provided herewith. The latter file contains the Pascal source for all the
new functions. Of course, these are coded in assembler in the MATHLIB unit.
If MATHLIB doesn't meet your floating point calculation needs please let us
know why. Thanks.
MATHLIB Documentation Page 4
INVOICE & REGISTRATION FOR MATHLIB VERSION 2.0
Please remit to: Waldman Sidelines
Cye H. Waldman
P.O. Box 231157
Encinitas, CA 92023-1157
LIMIT OF LIABILITY
The MATHLIB library (MATHLIB.TPU) is distributed as-is. The author
disclaims all warranties, expressed or implied. The author will
assume no liability for damages either from the direct use of this
product or as a consequence of the use of this product.
Please register one copy of MATHLIB for each user at your site.
MATHLIB Registration Qty. _____ @ $25.00 ea. = ____________
Calif. Residents Add 7.75% Sales Tax + ____________
Total Payment: ____________
Registered users will receive a disk with the Pascal source code and
assembled object code. Registered users will be notified of new
updates. Suggestions for extensions of the library are welcome as
well as requests for developments of similar libraries for other
languages. Comments are also welcome from those who elect not to
register. Thank you for using MATHLIB.
Name: ____________________________________________________________
Company: _________________________________________________________
Address: _________________________________________________________
Day Phone: _______________________ Eve: ________________________
Preferred Technical Support (Tel, CompuServe, etc.) _______________
COMMENTS AND SUGGESTIONS
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________
______________________________________________________________________